import java.util.Stack;

class MinStack {
    Stack<Integer> stack;
    Stack<Integer> minStack;
    public MinStack() {
        stack=new Stack<>();
        minStack=new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if (minStack.isEmpty() || val <= minStack.peek()) {
            minStack.push(val);
        }
    }

    public void pop() {
        if (stack.empty()){
            return;
        }else{
            int temp=stack.pop();
            if(temp==minStack.peek()){
                minStack.pop();
            }
        }
    }

    public int top() {
        if (stack.empty()){
            return -1;
        }else{
            return stack.peek();
        }
    }

    public int getMin() {
        if (minStack.empty()){
            return -1;
        }else{
            return minStack.peek();
        }
    }
}